function [Ra1f, Ra2f, Rbf, Comp1f, Comp21f, Comp22f, Comp3f, Comp41f, Comp42f, error]=obtainSedra (stage, stageType)
C=[0.47e-6, 1e-9, 1e-12, 1e-6, 1.2e-9, 1.2e-12, 1.5e-9, 1.5e-12, 1.8e-9, 1.8e-12, 10e-9, 10e-12, 10e-6, 100e-9, 100e-12, 100e-6, 1000e-12, 1000e-6, 12e-9, 12e-12, 120e-9, 120e-12, 15e-9, 150e-9, 150e-12, 18e-9, 18e-12, 180e-9, 180e-12, 2.2e-9, 2.2e-12, 2.2e-6, 2.7e-9, 2.7e-12, 22e-9, 22e-12, 22e-6, 220e-9, 220e-12, 220e-6, 2200e-6, 27e-9, 27e-12, 270e-9, 270e-12, 3.3e-9, 3.3e-12, 3.3e-6, 3.9e-9, 3.9e-12, 33e-9, 33e-12, 33e-6, 330e-9, 330e-12, 330e-6, 3300e-6, 39e-9, 39e-12, 390e-9, 390e-12, 4.7e-9, 4.7e-12, 4.7e-6, 47e-9, 47e-12, 47e-6, 470e-9, 470e-12, 470e-6, 4700e-6, 5.6e-9, 5.6e-12, 56e-9, 56e-12, 560e-9, 560e-12, 6.8e-9, 6.8e-12, 680e-9, 680e-12, 8.2e-9, 8.2e-12, 82e-9, 82e-12, 820e-12];
error=1;
w0=abs(stage.stagePoles(1));
Q=abs(stage.stagePoles(1)/(2*real(stage.stagePoles(1))));
if stageType==2 && ~isempty(stage.stageZeros)
    n2=(abs(stage.stagePoles(1))/abs(stage.stageZeros(1)))^2;
end

for j=2:Q+1
    i=1;
    Rf=[];
    if j~=floor(Q)
        Q0=Q/(j);
    else
        Q0=1;
    end
    K1=(1-Q0/Q)/(2*Q0^2);           % K-1 es K1
for t=1:length(C)
    R=2*Q0/(w0*C(t));
    if R>10 && R<100000
        ZC=1/(C(t)*w0);
        if ZC>10 && ZC<100000
            Cf(i)=C(t);
            Rf(i)=R;
            i=i+1;  
        end
    end
end

if stageType==3
     Comp3=Cf;
     Comp1=Rf/(4*Q0^2);
     if stage.stageZeros(1)==0
        m=stage.stageGain/(K1+1);
        k=0;
        n=0;
     else
        wz=abs(stage.stageZeros(1));
        k=stage.stageGain*stage.KtoAdd*(wz/w0)^2/(1-Q0/Q);
        n=k*(1-Q0/((K1+1)*Q));
        m=k*K1*(1+2*Q0*Q0*(w0/wz)^2)/(K1+1);
     end
     Comp4=Rf;
     if (k>=0 && k<=1) && (n>=0 && n<=1) && (m>=0 && n<=1)
     Comp21=(1-m)*Cf;
     Comp22=m*Cf;
     Comp42=Comp4/n;
     Comp41=Comp4/(1-n);
     end
elseif stageType==2
        R2=Rf;
        Comp1=Cf;
        Comp3=Rf;
        Comp4=Cf/(4*Q0^2);
        if isempty(stage.stageZeros)
%             Comp4=Comp4/2;
            m=stage.stageGain/((K1+1));
            k=0;
            n=0;
        else
           wz=abs(stage.stageZeros(1));
           k=n2/(1-Q0/Q);
           n=k*(1-Q0/(Q*(K1+1)));
           m=k*K1*(1+2*Q0*Q0*(wz/w0)^2)/(K1+1);
        end
        if (k>=0 && k<=1) && (n>=0 && n<=1) && (m>=0 && n<=1)
        Comp22=R2/m;
        Comp21=R2/(1-m);  
        Comp42=Comp4*n;
        Comp41=Comp4*(1-n);
        end
end
if (k>=0 && k<=1) && (n>=0 && n<=1) && (m>=0 && n<=1)
    break;
end

end
     i=1; 
     for Ra=logspace(2,4,50)
        Rb1=K1*Ra; 
        Raa(i)=Ra;
        Rb(i)=Rb1;
        i=i+1;
     end
     Ra1=Raa/(1-k);
     Ra2=Raa/k;

     error1=1;
     %Devuelvo un valor random
     %Ra1 Ra2 Rb
     for i=1:length(2*Ra1)   % Ponele
     p=random('unid',length(Ra1));
     if Ra1(p)>10 && Ra1(p)<300000 && Rb(p)>10 && Rb(p)<300000
        Ra1f=Ra1(p);
        Ra2f=Ra2(p);
        Rbf=Rb(p);
        error1=0;
        break;
     end
     end
     
     % El resto
     if (k>=0 && k<=1) && (n>=0 && n<=1) && (m>=0 && n<=1)
         for i=1:length(2*Comp1)   % Ponele
            p=random('unid',length(Comp1));
            if Comp1(p)<300000 && Comp21(p)<300000 && Comp22(p)<300000 && Comp3(p)<300000 && Comp41(p)<300000 && (Comp42(p)<300000 || Comp42(p)==inf && error1==0)
                 Comp1f=Comp1(p);
                 Comp21f=Comp21(p);
                 Comp22f=Comp22(p);
                 Comp3f=Comp3(p);
                 Comp41f=Comp41(p);
                 Comp42f=Comp42(p);
                 error=0;
                 break;
            end
         end
     end
     if error==1
         Ra1f=0;
         Ra2f=0;
         Rbf=0;
         Comp1f=0;
         Comp21f=0;
         Comp22f=0;
         Comp3f=0;
         Comp41f=0;
         Comp42f=0;
         error=1;
     end
end